use std::fs::File;

use super::*;

#[derive(Debug, Clone)]
pub struct AST{
    pub token_type: TokenType,
    pub token_str: Box<String>,
    pub line_no: i32,
    pub children: Box<Vec<AST>>,
}

impl AST {
    pub fn new<S:AsRef<str>>(token_type: TokenType, token_str: S, line_no: i32, children: Vec<AST>) -> Self {
        Self { token_type, token_str: Box::new(token_str.as_ref().to_owned()), line_no, children: Box::new(children) }
    }
    pub fn new2<S:AsRef<str>>(token_type: TokenType, token_str: S) -> Self {
        Self::new(token_type, token_str, i32::default(), Vec::default())
    }
    pub fn new3<S:AsRef<str>>(token_type: TokenType, token_str: S, children: Vec<AST>) -> Self {
        Self::new(token_type, token_str, i32::default(), children)
    }
    pub fn from_token(token: &Vec<Token>) -> Self{
        let t = token[0].clone();
        Self{
            token_type: t.token_type(),
            token_str: t.token_str().clone(),
            line_no: t.line_no(),
            children: Box::new(Vec::default()),
        }
    }
}

impl Default for AST {
    fn default() -> Self {
        Self{
            token_type: TokenType::EOF,
            token_str: Box::new(String::default()),
            line_no: 1,
            children: Box::new(Vec::default()),
        }
    }
}
